<script setup>
import {reactive, ref} from "vue";
import {POST, PUT} from "../api/index.js";
import {typeOptions} from "../utils/listData.js";

const dialogFormVisible = ref(false)
const emit = defineEmits(['ok'])
const form = reactive({
  id: '',
  trend: 0,
  level: '',
  stage: '',
  stockCode: '',
})

const open = (row) => {
  if(row.threndDTO) {
    form.id = row.threndDTO.id
    form.trend = row.threndDTO.trend
    form.level = row.threndDTO.level?.toString()
    form.stage = row.threndDTO.stage
  }

  form.stockCode = row.stockCode

  dialogFormVisible.value = true
}

const saveHandle = () => {
  let fn = form.id ? PUT : POST
  fn('/market/thrend', form).then(res => {
    dialogFormVisible.value = false
    emit('ok')
  })
}

defineExpose({
  open
})
</script>

<template>
  <el-dialog v-model="dialogFormVisible" title="编辑" width="500">
    <el-form :model="form" label-width="80">
      <el-form-item label="操作级别">
        <el-select
            v-model="form.level"
            placeholder="请选择"
        >
          <el-option label="无" value="0" />
          <el-option
              v-for="item in typeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="走势类型">
        <el-select v-model="form.trend">
          <el-option label="无" :value="0" />
          <el-option label="上涨" :value="1" />
          <el-option label="盘整" :value="2" />
          <el-option label="下跌" :value="3" />
        </el-select>
      </el-form-item>
      <el-form-item label="走势阶段">
        <el-select v-model="form.stage">
          <el-option label="无" value="" />
          <el-option label="a" value="a" />
          <el-option label="A" value="A" />
          <el-option label="b" value="b" />
          <el-option label="B" value="B" />
          <el-option label="c" value="c" />
          <el-option label="C" value="C" />
          <el-option label="d" value="d" />
          <el-option label="D" value="D" />
        </el-select>
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取消</el-button>
        <el-button type="primary" @click="saveHandle">
          确定
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<style scoped lang="scss">

</style>